package org.xue.snowmall.search.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.xue.snowmall.common.utils.R;
import org.xue.snowmall.search.entity.GoodsEntity;
import org.xue.snowmall.search.service.GoodsService;
import org.xue.snowmall.common.utils.PageUtils;


/**
 * 
 *
 * @author zy
 * @email 2067065884@qq.com
 * @date 2021-09-22 17:27:58
 */
@RestController
@RequestMapping("search/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("esList")
    public R esList(@RequestParam Map<String, Object> params) throws IOException {
        Integer page = Integer.parseInt((String) params.get("page"));
        Integer limit = Integer.parseInt((String) params.get("limit"));
        PageUtils<GoodsEntity> esList = goodsService.esList(null, page, limit);
        return R.ok().put("page",esList);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{psmId}")
    public R info(@PathVariable("psmId") Long psmId){
		GoodsEntity goods = goodsService.getById(psmId);

        return R.ok().put("goods", goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] psmIds){
		goodsService.removeByIds(Arrays.asList(psmIds));

        return R.ok();
    }

}
